RequestGuard xhrGuard = new RequestGuard(RequestType.XHR); selenium.getInterceptionProxy().registerInterceptor(xhrGuard); selenium.click(BUTTON_START);
Its purpose is to guard that the interaction of the user will raise specific request to the server. It differs between following types:
No Request
XHR Request (AJAX)
HTTP Request (regular HTTP)
You can create new RequestGuard with given type defined in constructor:
RequestGuard xhrGuard = new RequestGuard(RequestType.XHR); selenium.getInterceptionProxy().registerInterceptor(xhrGuard); selenium.click(BUTTON_START);
More intuitive and also preferred way of usage is the usage of Graphene Utility static members:
guardXhr(selenium).click(BUTTON_CAUSING_XHR); ... guardHttp(selenium).click(BUTTON_CAUSING_HTTP); ... selenium.click(ANY_BUTTON);
Internally, factory creates immutable copy of CommandInterceptionProxy and also AjaxSelenium and returns this modified copies, thereby the last call clicking to ANY_BUTTON will not be intercepted by any RequestGuard.
It brings simplicity to quite hard-to-understand topic.
Together with guarding the request type done, there is also the possibility to wait until the page will catch the given request type, ignoring all other requests.
For this purpose, you can again use Graphene Utility, similary to previous sample:
waitXhr(selenium).click(BUTTON_CAUSE_XHR); ... waitHttp(selenium).click(BUTTON_CAUSE_HTTP);
This is useful in cases, where you expect that also other request can be done.
For example you are relocating to new URL, but on the current page is still active using AJAX (triggering XMLHttpRequest).